package com.yh.csx.event.domain.event;

import com.yh.csx.event.common.exception.EventException;
import com.yh.csx.event.common.exception.ExceptionEnum;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author zhangsheng
 * @date 2021/8/20 17:21
 */
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum EventResultTypeNum {
    NORMAL(0, "正常状态"),
    CONSUMER_FAIL(1, "消费失败"),
    ;
    private Integer code;
    private String name;


    public static EventResultTypeNum getEventErrorTypeNum(Integer code) {
        return Arrays.stream(values()).filter(event -> event.getCode().equals(code))
                .findFirst().orElseThrow(() -> new EventException(ExceptionEnum.NO_STATUS_TYPE, null == code ? "null" : code.toString()));
    }
}
